package com.bolt.support.spring.jpa.jpql;


import com.bolt.support.query.conditions.domain.SqlClause;

public class OrderClause implements SqlClause<String> {

    private final SqlOrder order;

    private final SqlClause<?> columnClause;

    public OrderClause(SqlOrder order, SqlClause<?> columnClause) {
        this.order = order;
        this.columnClause = columnClause;
    }

    public OrderClause(String direction, SqlClause<?> columnClause){
        this.order = SqlOrder.fromString(direction);
        this.columnClause = columnClause;
    }

    @Override
    public String render(boolean addAlias) {
        StringBuilder builder = new StringBuilder();
        builder.append(columnClause.render(addAlias));
        builder.append(order == SqlOrder.ASC ? " asc" : " desc");
        return builder.toString();
    }
}

 